# -*- coding: utf-8 -*-
# !/usr/bin/python3
"""
Author :      wu
Description :
"""

from datetime import datetime

import tensorflow as tf


def time_test_with_tf1():

    g = tf.compat.v1.Graph()
    with g.as_default():
        x = tf.compat.v1.placeholder(name="x", shape=[], dtype=tf.string)
        y = tf.compat.v1.placeholder(name="y", shape=[], dtype=tf.string)
        z = tf.strings.join([x, y], name="join", separator=" ")

    with tf.compat.v1.Session(graph=g) as session:
        res = session.run(fetches=z, feed_dict={x: "hello", y: "world"})
        print("tf1 print = ", res, type(res))


def time_test_with_tf2():

    x = tf.constant("hello", dtype=tf.string)
    y = tf.constant("world", dtype=tf.string)
    z = tf.strings.join([x, y], separator=" ")

    print("python print = ", z)
    tf.print("tf.print = ", z)


@tf.function
def str_join(x, y):
    z = tf.strings.join([x, y], separator=" ")
    tf.print("tf.print = ", z)

    return z


def time_test_with_tf2_autograph():

    x = tf.constant("hello", dtype=tf.string)
    y = tf.constant("world", dtype=tf.string)
    res = str_join(x, y)
    print(res)


def main():

    start_time = datetime.now()
    time_test_with_tf1()
    end_time_t1 = datetime.now()
    time_test_with_tf2()
    end_time_t2 = datetime.now()
    time_test_with_tf2_autograph()
    end_time_t2_autograph = datetime.now()

    print("tfv1 time cost: ".format(end_time_t1 - start_time))
    print("tfv2 time cost: ".format(end_time_t2 - end_time_t1))
    print("tfv2 autograph time cost: ".format(end_time_t2_autograph - end_time_t2))


if __name__ == "__main__":
    main()
